<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;
use App\Models\Comment;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentController extends Controller
{
    /**
     * 评论list 列表页 的显示
     */
    public function getIndex(Request $request)
    {
        // 查询评论数据库   分页
        $comment = DB::table('comment')
        ->orderBy('commentid')
        ->where(function($query)use($request){
            $query->where('goodsid','like','%'.$request->input('keywords').'%');
        })
        ->paginate($request->input('num',10));
        return view('content.index',['comment'=>$comment,'request'=>$request->all()]);
    }

    /**
     * 删除商品
     */
    public function getDelete($commentid)
    {
        $res=DB::table('comment')->where('commentid',$commentid)->delete();
        
        if($res){
            return redirect('/comment/index')->with('success','评论删除成功');
        }else{
            return back()->with('error','评论删除失败');
        }
    }


}
